package udp;

import java.net.*;

public class Send {
    public static void main(String[] args) throws Exception {
        //1.创建DatagramSocket对象,构造方法中需要指定端口号
        DatagramSocket socket = new DatagramSocket(8888);

        //2.创建DatagramPacket对象
        String msg = "你猜我要说啥";
        byte[] bytes = msg.getBytes();
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length, InetAddress.getByName("127.0.0.1"), 9999);

        //3.发送数据
        socket.send(packet);

        //4.释放资源
        socket.close();

    }
}
